import LayerManager from "./LayerManager"
import LayerInfo from "./LayerInfo"
import BaseView from "../base/view/BaseView";
class StackLayerManager extends LayerManager {
    constructor(){
        super();
    }

    //添加layer
    pushView(layerInfo:LayerInfo){
        // this.popView();
        if(layerInfo.isHideBg()){
            let last = this.list[this.list.length - 1];
            if(last){
                last.setVisible(!layerInfo.isHideBg());
            }
        }
        this.list.push(layerInfo);
        this.root.addChild(layerInfo.getNode());
    }

    // 移除layer
    popView(view:BaseView): boolean{
        if(!view){
            if(this.list.length > 0){
                let layerInfo = this.list.pop();
                layerInfo.destroy(); 
                if(layerInfo.isHideBg()){
                    let last = this.list[this.list.length - 1];
                    if(last){
                        last.setVisible(layerInfo.isHideBg());
                    }
                }           
                return true;
            }else{
                return false;
            }
        }else{
            return this.removeView(view);
        }
    }

    popAll() {
        let depth = this.list.length;
        for (let i = 0; i < depth; i++) {
            let layerInfo = this.list.pop();
            layerInfo.destroy();
        }
    }
}
export = StackLayerManager